class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> st = new Stack<>();
        for(int i = 0; i < tokens.length; i++){
            String str = tokens[i];
            if(str.equals("+") || str.equals("-") || str.equals("/") || str.equals("*")){
                int right = st.pop();
                int left = st.pop();
                switch(str){
                    case "+":
                        st.push(left + right);
                        break;
                    case "-":  
                        st.push(left - right);
                        break;
                    case "*":
                        st.push(left * right);
                        break;
                    case "/":
                        st.push(left / right);
                        break;
                }
            }else{
                st.push(Integer.parseInt(str));
            }
        }
        return st.peek();
    }
}
